//
//  ViewController.m
//  DesignPattern
//
//  Created by jun on 2021/4/16.
//

#import "ViewController.h"
#import "MVC-C.h"
#import "MVP-C.h"
#import "MVVM-C.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UITableView *tableview = [[UITableView alloc]initWithFrame:self.view.frame];
    tableview.delegate =self;
    tableview.dataSource = self;
    [self.view addSubview:tableview];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (indexPath.row == 0) {
        cell.textLabel.text = @"MVC";
    }else if(indexPath.row == 1){
        cell.textLabel.text = @"MVP";
    }else{
        cell.textLabel.text = @"MVVM";
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIViewController *ctl;
    
    if (indexPath.row == 0) {
        ctl = [MVC_C new];
        ctl.title = @"MVC";
    }else if(indexPath.row == 1){
        ctl = [MVP_C new];
        ctl.title = @"MVP";
    }else{
        ctl = [MVVM_C new];
        ctl.title = @"MVVM";
    }
    
    [self.navigationController pushViewController:ctl animated:YES];
}

@end
